package String;

public class StringDemo {
    public static void main(String[] args) {
//        String s1 = "1234abc";
//        String s2 = "1234abc";
//        String s3 = "1234abc";
//
//        System.out.println(s1 == s2);
//        System.out.println(s1 == s3);
//        System.out.println(s2 == s3);
//        s1 = s1 + "!";
//        System.out.println(s1 == s2);
        String s1 = "123abc";//堆中创建123abc字符量对象，并缓存到常量池中
        //编译器在编译时，若发现是两个字面量相连，则会直接连接好并将结果保存起来
        //如下语句会被编译成：String s2 = "123abc"
        String s2 = "123"+"abc";
        System.out.println(s1 == s2);
        String s3 = "123";
        //因为s3是一个变量，所以在编译时不会直接编译
        String s4 = s3+"abc";//创建一个新的地址
        System.out.println(s1 == s4);

        String s5 = " abc123 ";
        String s6 = "abc123";
        System.out.println(s5.equals(s6));
    }
}
